<?php
if ($_SESSION['niveauAuth']<>'3') {
//insertion sim
$pathSearch = sprintf(
	'%s%s/*.csv',
	MM_SIM_PATH,
	filter_input(INPUT_POST, 'import-sim')
);
$files = glob($pathSearch);
rsort($files);
$file = $files[0];

//if (strstr($file, "sim")){ 
$ligne = 1; // compteur de ligne
$fic = fopen($file, "a+");
while($tab=fgetcsv($fic,1024,';'))
{
$champs = count($tab);//nombre de champ dans la ligne en question
$ligne ++;
$req = $bdd->prepare('INSERT INTO carte_sim(transatelId,msisdn,releases,iccld,hlrstatus,pin,puk)
		VALUES(:transatelId, :msisdn, :releases, :iccld, :hlrstatus, :pin, :puk)');

$req->execute(array(
		'transatelId' => $tab[0],
		'msisdn' => $tab[1],
		'releases' => $tab[2],
		'iccld' => $tab[3],
		'hlrstatus' => $tab[4],
		'pin' => $tab[5],
		'puk' => $tab[6],
));

}
//}
if ($req){
	$message = $ligne. " lignes d'insérées";
} else {
	 $error = "le fichier ne s'est pas importer";
}

echo $twig->render('import-sim.html',
		array('message' => $message,
				'ligne' => $ligne,
				'error' => $error));

}
else {
	redirect("home-admin");
}

